/*     */ package com.zimbra.cs.stats;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.stats.StatsDumperDataSource;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ThreadStats
/*     */   implements StatsDumperDataSource
/*     */ {
/*     */   private String mFilename;
/*     */   
/*     */   public ThreadStats(String filename)
/*     */   {
/*  47 */     this.mFilename = filename;
/*     */   }
/*     */   
/*     */   public String getFilename() {
/*  51 */     return this.mFilename;
/*     */   }
/*     */   
/*     */   public String getHeader() {
/*  55 */     return StringUtil.join(",", getThreadNamePrefixes()) + ",other,total";
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Collection<String> getDataLines()
/*     */   {
/*  64 */     String[] threadNamePrefixes = getThreadNamePrefixes();
/*  65 */     Map<String, Integer> threadCount = new LinkedHashMap();
/*  66 */     for (String prefix : threadNamePrefixes) {
/*  67 */       threadCount.put(prefix, Integer.valueOf(0));
/*     */     }
/*  69 */     threadCount.put("other", Integer.valueOf(0));
/*     */     
/*     */ 
/*  72 */     ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
/*  73 */     while (root.getParent() != null) {
/*  74 */       root = root.getParent();
/*     */     }
/*     */     
/*     */ 
/*  78 */     Thread[] threads = new Thread[root.activeCount() * 2];
/*  79 */     int numThreads = root.enumerate(threads, true);
/*  80 */     for (int i = 0; i < numThreads; i++) {
/*  81 */       Thread thread = threads[i];
/*  82 */       String threadName = thread.getName();
/*  83 */       boolean found = false;
/*  84 */       for (String prefix : threadNamePrefixes)
/*     */       {
/*  86 */         if ((threadName != null) && (threadName.startsWith(prefix))) {
/*  87 */           threadCount.put(prefix, Integer.valueOf(((Integer)threadCount.get(prefix)).intValue() + 1));
/*  88 */           found = true;
/*  89 */           break;
/*     */         }
/*     */       }
/*  92 */       if (!found) {
/*  93 */         threadCount.put("other", Integer.valueOf(((Integer)threadCount.get("other")).intValue() + 1));
/*     */       }
/*     */     }
/*     */     
/*  97 */     StringBuilder buf = new StringBuilder();
/*  98 */     for (String prefix : threadCount.keySet()) {
/*  99 */       buf.append(threadCount.get(prefix));
/* 100 */       buf.append(',');
/*     */     }
/* 102 */     buf.append(numThreads);
/*     */     
/*     */ 
/* 105 */     List<String> retVal = new ArrayList(1);
/* 106 */     retVal.add(buf.toString());
/* 107 */     return retVal;
/*     */   }
/*     */   
/*     */   public boolean hasTimestampColumn() {
/* 111 */     return true;
/*     */   }
/*     */   
/*     */   private String[] getThreadNamePrefixes() {
/*     */     try {
/* 116 */       return Provisioning.getInstance().getLocalServer().getStatThreadNamePrefix();
/*     */     } catch (ServiceException e) {
/* 118 */       ZimbraLog.perf.warn("Unable to determine thread name prefixes.", e); }
/* 119 */     return new String[0];
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/stats/ThreadStats.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */